package com.yanqu.road.dao.impl.activity.springdinner;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.springdinner.SpringDinnerBallConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SpringDinnerConfigDaoImpl extends TempDao {

    public static String getBallCommentSql = "select * from t_s_activity_spring_dinner_ball where activityId= ?";
    public Map<Integer, SpringDinnerBallConfig> getBallMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, SpringDinnerBallConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getBallCommentSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SpringDinnerBallConfig data = new SpringDinnerBallConfig();
                data.setId(rs.getInt("id"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setType(rs.getInt("type"));
                data.setQuality(rs.getInt("quality"));
                data.setPic(rs.getInt("pic"));
                data.setIcon(rs.getInt("icon"));
                data.setWeight(rs.getInt("weight"));
                data.setScore(rs.getLong("score"));
                data.setWidth(rs.getInt("width"));
                result.put(data.getIcon(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }
}
